package com.medical.wechat.service.impl;

import com.medical.common.CustomizeException;
import com.medical.wechat.mapper.WechatTemplateMapper;
import com.medical.wechat.model.WechatTemplate;
import com.medical.wechat.service.WechatTemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;
import java.util.UUID;

@SuppressWarnings("SpringJavaAutowiringInspection")
@Service("wechatTemplateService")
public class WechatTemplateServiceImpl implements WechatTemplateService{

    @Autowired
    private WechatTemplateMapper wechatTemplateMapper;

    public WechatTemplate selectById(String id){
        return wechatTemplateMapper.selectById(id);
    }


    public void createWechatTemplate(WechatTemplate wechatTemplate) {
        if(StringUtils.isEmpty(wechatTemplate.getId())){
            wechatTemplate.setId(UUID.randomUUID().toString());
        }
        WechatTemplate wechatTemplateTemp = wechatTemplateMapper.selectById(wechatTemplate.getId());
        if(wechatTemplateTemp!=null){

            wechatTemplateMapper.updateById(wechatTemplate);

        }else{
            wechatTemplateMapper.insertWechatTemplate(wechatTemplate);
        }
    }
    public List<WechatTemplate> findByAccountId(String accountId) {
        return wechatTemplateMapper.selectByAccountId(accountId);
    }

    public void updateById(WechatTemplate wechatTemplate){
        wechatTemplateMapper.updateById(wechatTemplate);
    }
    public void deleteById(String id){
        wechatTemplateMapper.deleteById(id);
    }
}
